<template>
  <view class="edit-profile-page">
    <!-- 顶部导航 -->
    <view class="nav-bar">
      <text class="back-btn" @click="goBack">← 返回</text>
      <text class="title">编辑资料</text>
      <text class="save-btn" @click="saveProfile">保存</text>
    </view>

    <!-- 头像编辑区域 -->
    <view class="avatar-section">
      <view class="avatar-container">
        <image 
          class="avatar" 
          :src="userInfo.avatar || defaultAvatar" 
          mode="aspectFill"
        ></image>
      </view>
      <button class="upload-btn" @click="chooseAvatar">上传头像</button>
    </view>

    <!-- 表单区域 -->
    <view class="form-section">
      <view class="form-item">
        <text class="label">昵称：</text>
        <input 
          class="input" 
          v-model="userInfo.name" 
          placeholder="请输入昵称"
        />
      </view>
      <view class="form-item">
        <text class="label">ID：</text>
        <input 
          class="input" 
          v-model="userInfo.userId" 
          placeholder="请输入ID"
          disabled  
        />
      </view>
      <view class="form-item">
        <text class="label">等级：</text>
        <text class="value">{{ userInfo.level || '未设置' }}</text>
      </view>
      <view class="form-item">
        <text class="label">VIP：</text>
        <text class="value">{{ userInfo.vip ? '是' : '否' }}</text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      defaultAvatar: 'https://cdn-icons-png.flaticon.com/512/149/149071.png', // 默认头像
      userInfo: {
        name: '张仁菊',
        userId: '2025001',
        level: 5,
        vip: true,
        avatar: '' // 若有默认头像可在此赋值
      }
    }
  },
  methods: {
    // 返回个人中心
    goBack() {
      uni.navigateBack();
    },
    // 选择头像
    chooseAvatar() {
      uni.chooseImage({
        count: 1,
        sizeType: ['original', 'compressed'],
        sourceType: ['album', 'camera'],
        success: (res) => {
          const tempFilePath = res.tempFilePaths[0];
          this.userInfo.avatar = tempFilePath; // 临时显示，实际需上传到服务器
          // 这里可调用上传接口，将 tempFilePath 上传并更新用户头像
        }
      });
    },
    // 保存资料
    saveProfile() {
      // 模拟保存逻辑，实际需调用接口更新用户信息
      uni.showToast({
        title: '资料保存成功',
        icon: 'success'
      });
      // 保存后可更新个人中心数据（若有全局状态管理可同步）
      this.goBack();
    }
  }
}
</script>

<style scoped>
/* 页面基础样式 */
.edit-profile-page {
  background-color: #f5f7fa;
  min-height: 100vh;
}

/* 导航栏 */
.nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 88rpx;
  padding: 0 24rpx;
  background: linear-gradient(90deg, #2c82c9, #3a9ee6);
  color: #fff;
}
.back-btn {
  font-size: 32rpx;
}
.title {
  font-size: 36rpx;
  font-weight: bold;
}
.save-btn {
  font-size: 32rpx;
  color: #fff;
}

/* 头像区域 */
.avatar-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40rpx 0;
  background-color: #fff;
  margin: 24rpx;
  border-radius: 12rpx;
  box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.05);
}
.avatar-container {
  width: 160rpx;
  height: 160rpx;
  border-radius: 50%;
  overflow: hidden;
  margin-bottom: 24rpx;
  box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.1);
}
.avatar {
  width: 100%;
  height: 100%;
}
.upload-btn {
  background-color: #007bff;
  color: #fff;
  padding: 16rpx 32rpx;
  border-radius: 8rpx;
  font-size: 28rpx;
}

/* 表单区域 */
.form-section {
  background-color: #fff;
  margin: 0 24rpx 24rpx 24rpx;
  border-radius: 12rpx;
  box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.05);
}
.form-item {
  display: flex;
  align-items: center;
  padding: 24rpx;
  border-bottom: 1px solid #f5f5f5;
}
.label {
  font-size: 28rpx;
  color: #333;
  width: 120rpx;
}
.input {
  flex: 1;
  height: 60rpx;
  line-height: 60rpx;
  border: 1px solid #eee;
  border-radius: 8rpx;
  padding: 0 16rpx;
  font-size: 26rpx;
}
.value {
  flex: 1;
  font-size: 26rpx;
  color: #666;
}
</style>